const util = require('../../utils/util')

// components/card/card.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    url: {type: String},
    name: {type: String},
    local: {type: String},
    distance: {type: String, value: 0},
    galleryList: {type: Array},
    radius: {type: Boolean, value: true},
    shadow: {type: Boolean, value: true}
  },

  observers: {
    "distance": function(val) {
      if(util.nonNull(val)) {
        if (val == -1) {
          this.setData({_distance: '定位失败'})
        }
        else {
          this.setData({_distance: val>=1000? (val/1000).toFixed(2)+'km' : val+'m'})
        }
      }
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    _distance: '0m',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    _phoneOnTap(){
      this.triggerEvent("phoneOnTap")
    },
    _naviOnTap(){
      this.triggerEvent("naviOnTap")
    },
    _preview(event) {
      let currentUrl = event.currentTarget.dataset.src
      wx.previewImage({
        current: currentUrl,
        urls: this.data.galleryList.length > 0 ? this.data.galleryList : [currentUrl]
      })
    }
  },
})
